#include <dbg.h>
#include <gtest/gtest.h>

using namespace std;

class Solution {
public:
    int numIdenticalPairs(vector<int>& nums) {
        unordered_map<int, int> countMap;

        int res = 0;
        for (int x : nums) {
            res +=
                countMap[x]++;  // 累加当前元素的出现次数，并更新映射表中的计数
            dbg(countMap);
        }
        return res;
    }
};

TEST(TEST1_numIdenticalPairs_Test, numIdenticalPairs) {
    Solution s;

    vector<int> nums{1, 2, 3, 1, 1, 3};
    EXPECT_EQ(s.numIdenticalPairs(nums), 4);
}

TEST(TEST2_numIdenticalPairs_Test, numIdenticalPairs) {
    Solution s;

    vector<int> nums{1, 1, 1, 1};
    EXPECT_EQ(s.numIdenticalPairs(nums), 6);
}

TEST(TEST3_numIdenticalPairs_Test, numIdenticalPairs) {
    Solution s;

    vector<int> nums{1, 2, 3};
    EXPECT_EQ(s.numIdenticalPairs(nums), 0);
}

int main(int argc, char** argv) {
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}